package com.example.demo.controller;


import com.example.demo.entity.Book;
import com.example.demo.entity.Category;
import com.example.demo.entity.User;
import com.example.demo.service.BookService;
import com.example.demo.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2020-11-28
 */
@RestController
@RequestMapping("/category")
@CrossOrigin(origins="http://localhost:8080")
public class CategoryController {
    @Autowired
    CategoryService aha;
    @Autowired
    BookService bookService;
    @GetMapping("/xixi")
    public Object getAll(){
        List<Category> list = aha.list();
        Category u1 = list.get(1);
        list.set(1,list.get(0));
        list.set(0,u1);
        return list;
    }

    @GetMapping("/getcategory_by_id")
    public Object getcategory_by_id(Integer id){
        List<Category> list = aha.list();
        for(Category c:list)
        {
            if(c.getId()==id)
            {

                return c.getName();
            }
        }

        return  list;

    }
}

